package mars.activity;

import java.util.ArrayList;
import java.util.HashMap;

import bear.download.Circleread;
import bear.download.Searchread;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class Search extends ListActivity{
private Button circlename,user_name,books,turnup,turndown;
private TextView pages;
private EditText edit1;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.search);
		books=(Button)findViewById(R.id.books);
		user_name=(Button)findViewById(R.id.user_name);
		circlename=(Button)findViewById(R.id.circlename);
		turnup=(Button)findViewById(R.id.turnup);
		turndown=(Button)findViewById(R.id.turndown);
		pages=(TextView)findViewById(R.id.pages);
		edit1=(EditText)findViewById(R.id.edit1);
		Intent intget=getIntent();
		String nr=intget.getStringExtra("gj");
		edit1.setText(nr);
		
		books.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View arg0) {
				// TODO Auto-generated method stub				
			}
			});
		user_name.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View arg0) {
				// TODO Auto-generated method stub				
			}
			});
		circlename.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View arg0) {
				// TODO Auto-generated method stub				
			}
			});
		turnup.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View arg0) {
				// TODO Auto-generated method stub				
			}
			});
		turndown.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View arg0) {
				// TODO Auto-generated method stub				
			}
			});
		//String seaechloushiids[] = Searchread.seaechloushiid1.split("\\$");
		String seaechloushinames[]=Searchread.seaechloushiname1.split("\\$");
		String seaechloushicounts[]=Searchread.seaechloushicount1.split("\\$");
		String seaechloushicategorys[]=Searchread.seaechloushicategory1.split("\\$");
		String createuser[]=Searchread.createuser1.split("\\$");
		
		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		for(int i=0;i<Searchread.n;i++){
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("cname",seaechloushinames[i] );
		//map.put("shu", "yes");
		map.put("lei", getString(R.string.leixing)+seaechloushicategorys[i]);
		if(Activity1.danxuansou=="2"){
		map.put("yonghu", getString(R.string.csu)+createuser[i]);
		}else {
			map.put("yonghu", "");
		}
		map.put("chuang", getString(R.string.ren)+seaechloushicounts[i]);
		list.add(map);
		}
		SimpleAdapter listAdapter = new SimpleAdapter(this, list,
				R.layout.secher, new String[] { "cname", "shu" ,"lei","yonghu","chuang"},
				new int[] { R.id.itemname,R.id.jiaru,R.id.lei,R.id.yonghu,R.id.chuang});
		setListAdapter(listAdapter);
	}

	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		menu.add(0,1,1,R.string.exit);
		menu.add(0,2,2,R.string.options);
		menu.add(0,3,3,R.string.help);
		return super.onCreateOptionsMenu(menu);
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		if(item.getItemId()==1){
			Intent startMain = new Intent(Intent.ACTION_MAIN);
			startMain.addCategory(Intent.CATEGORY_HOME);
			startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			startActivity(startMain);
			System.exit(0);
		}else if(item.getItemId()==2){
			item.setIntent(new Intent(this, Options.class));
		}else if(item.getItemId()==3){
			item.setIntent(new Intent(this, Help.class));
		}
		return super.onOptionsItemSelected(item);
	}
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		//System.out.println("id----------------" + id);
		//System.out.println("position----------" + position);
	}
}
